<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="filters">
        <el-form-item>
          <el-input v-model="filters.keyword" placeholder="关键字"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="seach">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleAdd">新增</el-button>
        </el-form-item>
      </el-form>
    </el-col>

    <!--列表-->
    <el-table :data="systemdictionarytypes" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;"
   @row-dblclick="popup"
    >
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column type="index" width="60">
      </el-table-column>
      <el-table-column prop="name" label="数据字典名" width="480" sortable>
      </el-table-column>
      <el-table-column prop="sn" label="编号" width="480" sortable>
      </el-table-column>
      <el-table-column label="操作" >
        <template scope="scope">
          <el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button>
      <el-pagination layout="prev, pager, next"
                     @current-change="handleCurrentChange"
                     :page-size="pageSize"
                     :total="total"
                     style="float:right;">
      </el-pagination>
    </el-col>

    <!--编辑界面-->
    <el-dialog :title="yoyo" :visible.sync="systemdictionarytypeFormVisible" :close-on-click-modal="false">
      <el-form :model="systemdictionarytypeForm" label-width="80px" :rules="systemdictionarytypeFormRules" ref="systemdictionarytypeForm">
        <el-form-item label=" 字典名" prop="name">
          <el-input v-model="systemdictionarytypeForm.name" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="编号" prop="sn">
          <el-input v-model="systemdictionarytypeForm.sn" auto-complete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="systemdictionarytypeFormVisible = false">取消</el-button>
        <el-button type="primary" @click.native="systemdictionarytypeSubmit" :loading="systemdictionarytypeLoading">提交</el-button>
      </div>
    </el-dialog>



    <!--抽屉  新增  -->
    <el-dialog :title="yoyo" :visible.sync="systemdictionarydetailsFormVisible" :close-on-click-modal="false">
      <el-form :model="systemdictionarydetailForm" label-width="80px" :rules="systemdictionarydetailFormRules" ref="systemdictionarydetailForm">
        <el-form-item label=" 明细名" prop="name">
          <el-input v-model="systemdictionarydetailForm.name" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="类型编号" prop="sn">
          <el-input v-model="systemdictionarydetailForm.types_id" auto-complete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="systemdictionarydetailsFormVisible = false">取消</el-button>
        <el-button type="primary" @click.native="systemdictionarydetailsSubmit" :loading="systemdictionarydetailLoading">提交</el-button>
      </div>
    </el-dialog>







    <el-drawer
        title="明细管理"
        :visible.sync="table"
        direction="rtl"
        size="60%">


      <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
        <el-form :inline="true" :model="fil">
          <el-form-item>
            <el-input v-model="fil.keyword" placeholder="关键字"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" v-on:click="sea">查询</el-button>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="han">新增</el-button>
          </el-form-item>
        </el-form>
      </el-col>









      <!--列表-->
      <el-table :data="systemdictionarydetails" highlight-current-row v-loading="listb" @selection-change="selsChan" style="width: 100%;">
        <el-table-column type="selection" width="55">
        </el-table-column>
        <el-table-column type="index" width="60">
        </el-table-column>
        <el-table-column prop="name" label="明细名" width="580" sortable>
        </el-table-column>
        <el-table-column label="操作" >
          <template scope="scope">
            <el-button size="small" @click="handle(scope.$index, scope.row)">编辑</el-button>
            <el-button type="danger" size="small" @click="handleromve(scope.$index, scope.row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>




      <el-col :span="24" class="toolbar">
        <el-button type="danger" @click="bat" :disabled="this.se.length===0">批量删除</el-button>

        <el-pagination layout="prev, pager, next"
                       @current-change="handl"
                       :page-size="size"
                       :total="tot"
                       style="float:right;">
        </el-pagination>
      </el-col>
    </el-drawer>




























  </section>
</template>

<script>

export default {
  data() {
    return {
      fil:{
        keyword: ''
      },
      filters: {
        keyword: ''
      },
      systemdictionarydetails:[],
      systemdictionarytypes:[],
      yoyo:"",
      ids:0,
      total: 0,
      tot: 0,
      size:5,
      idage:1,
      pageSize:5,
      currentPage: 1,
      listb:false,
      listLoading: false,
      se:[],
      sels: [],//列表选中行
      table:false,
      systemdictionarytypeFormVisible: false,//编辑界面是否显示
      systemdictionarytypeLoading: false,

      systemdictionarydetailsFormVisible: false,//编辑界面是否显示
      systemdictionarydetailLoading: false,


      systemdictionarytypeFormRules: {
        name: [
          { required: true, message: '请输入字典名称', trigger: 'blur' }
        ],
        sn: [
          { required: true, message: '请输入编号', trigger: 'blur' }
        ]
      },
      systemdictionarydetailFormRules: {
        name: [
          { required: true, message: '请输入明细名', trigger: 'blur' }
        ],
        types_id: [
          { required: true, message: '请输入类型编号', trigger: 'blur' }
        ]
      },
      systemdictionarydetailForm: {
        id: null,
        name: "",
        types_id:0,
        state: 0,
        manager: null,
        parent: null,
      },


      //编辑界面数据
      systemdictionarytypeForm: {
        id: null,
        sn: "",
        name: "",
        state: 0,
        manager: null,
        parent: null,
      },
    }
  },


  methods: {

    sea(){
      this.idage = 1;

      this. getSystemdictionarydetail();

    },
    getSystemdictionarydetail() {
      let para = {
        idage: this.idage,
        keyword: this.fil.keyword,
        size:this.size,
        ids:this.ids,

      };
      this.listb = true;//开启忙等框
      this.$http.post("/systemdictionarydetail",para)
          .then(result=>{
            result = result.data;
            this.systemdictionarydetails = result.rows;
            this.listb = false;//关闭忙等框

            this.tot = result.tot;

          })
          .catch(result=>{
            console.log(result);
            alert("系统错误！");
          })

    },













    popup(row, column, event){
      this.table=true;
      this.ids=row.id
      this.listb = true;//开启忙等框
      this.$http.get("/systemdictionarydetail/"+this.ids)
          .then(result=>{
            result = result.data;//PageList{total rows}

            this.systemdictionarydetails = result;
            /*console.log( this.systemdictionarydetails)*/
            this.listb = false;//关闭忙等框
            this.tot = result.tot;

          })
          .catch(result=>{
            console.log(result);
            alert("系统错误！");
          })
    this. getSystemdictionarydetail();



    },
    handleCurrentChange(val) {
      this.currentPage= val;

      this.getSystemdictionarytype();
    },
    handl(val) {
      this.idage= val;

      this.getSystemdictionarydetail()
    },

    seach(){
      this.currentPage = 1;
      this.getSystemdictionarytype();
    },


    //获取部门列表
    getSystemdictionarytype() {
      let para = {
        currentPage: this.currentPage,
        keyword: this.filters.keyword,
        pageSize:this.pageSize
      };
      this.listLoading = true;//开启忙等框
      this.$http.post("/systemdictionarytype",para)
          .then(result=>{
            result = result.data;//PageList{total rows}
            this.systemdictionarytypes = result.rows;
            this.listLoading = false;//关闭忙等框
            this.total = result.total;

          })
          .catch(result=>{
            console.log(result);
            alert("系统错误！");
          })

    },
    handleromve:function (index, row) {
      this.$confirm('确认删除该记录吗?', '温馨提示', {
        type: 'warning'
      }).then(() => {//点击确定
        this.listb = true;//开启忙等框
        //NProgress.start();
        this.$http.delete("/systemdictionarydetail/"+row.id)
            .then(result=>{
              //1.关闭忙等
              this.listb = false;
              //判断业务操作是否正常
              result  = result.data;//AjaxResult  {success:false,message:操作失败}
              if(result.success){
                this.$message({
                  message: '删除成功',
                  type: 'success'
                });
              }else{
                this.$message({
                  message: result.message,//提示我们自己的业务错
                  type: 'error'
                });
              }
              //2.刷新页面
              //是否需要重新刷新页面   要  定位到第一页
              this.idage= 1;
              this.getids();
            })
            .catch(result=>{
              this.listb = false;
              //NProgress.done();
              this.$message({
                message: '删除失败',
                type: 'error'
              });
              //失败了是否需要重新刷新页面   要  定位到第一页
              this.idage= 1;
              this.getids();
            })
      }).catch(() => {//点击取消

      });
    },


    //删除
    handleDel: function (index, row) {
      this.$confirm('确认删除该记录吗?', '温馨提示', {
        type: 'warning'
      }).then(() => {//点击确定
        this.listLoading = true;//开启忙等框


        this.$http.delete("/systemdictionarytype/"+row.id)
            .then(result=>{
              //1.关闭忙等
              this.listLoading = false;
              //判断业务操作是否正常
              result  = result.data;//AjaxResult  {success:false,message:操作失败}
              if(result.success){
                this.$message({
                  message: '删除成功',
                  type: 'success'
                });
              }else{
                this.$message({
                  message: result.message,//提示我们自己的业务错
                  type: 'error'
                });
              }
              //2.刷新页面
              //是否需要重新刷新页面   要  定位到第一页
              this.currentPage= 1;
              this.getSystemdictionarytype();
            })
            .catch(result=>{
              this.listLoading = false;
              //NProgress.done();
              this.$message({
                message: '删除失败',
                type: 'error'
              });
              //失败了是否需要重新刷新页面   要  定位到第一页
              this.currentPage= 1;
              this.getSystemdictionarytype();
            })
      }).catch(() => {//点击取消

      });
    },



    //显示编辑界面 抽屉
    handle: function (index, row) {
      console.log(row)
      this.yoyo="编辑";
      this.systemdictionarydetailsFormVisible = true;
      //Object.assign 克隆
      this.systemdictionarydetailForm = Object.assign({}, row);//回显

    },
    han: function () {

      this.yoyo="新增";
      this.systemdictionarydetailsFormVisible = true;
      this.systemdictionarydetailForm = {//清空历史遗留数据
        id: null,
        name: "",
        types_id:this.ids,
        state: 0,
        manager: null,
        parent: null,
      };
    },

    systemdictionarydetailsSubmit: function () {
      this.$refs.systemdictionarydetailForm.validate((valid) => {
        if (valid) {
          this.$confirm('确认提交吗？', '提示', {}).then(() => {
            this.systemdictionarydetailLoading = true;
            //NProgress.start();
            let para = Object.assign({}, this.systemdictionarydetailForm);
            //下午要用

            this.$http.put("/systemdictionarydetail",para)
                .then(result=>{
                  //1.关闭忙等
                  this.listb = false;
                  //判断业务操作是否正常
                  result  = result.data;//AjaxResult  {success:false,message:操作失败}
                  if(result.success){
                    this.systemdictionarydetailLoading = false;
                    this.systemdictionarydetailsFormVisible = false;
                    this.$message({
                      message: '操作成功',
                      type: 'success'
                    });
                  }else{
                    this.systemdictionarydetailLoading = false;
                    this.$message({
                      message: result.message,//提示我们自己的业务错
                      type: 'error'
                    });
                  }
                  //2.刷新页面
                  //是否需要重新刷新页面   要  定位到第一页
                  this.idage= 1;
                  this.fil.keyword="";
                  this.getids();
                })
                .catch(result=>{
                  this.systemdictionarydetailLoading = false;
                  this.$message({
                    message: '操作失败',
                    type: 'error'
                  });
                  //失败了是否需要重新刷新页面   要  定位到第一页
                  this.idage= 1;
                  this.fil.keyword="";
                  this.getids();
                })
          });
        }
      });
    },

























    //显示编辑界面
    handleEdit: function (index, row) {
       
      this.yoyo="编辑";
      this.systemdictionarytypeFormVisible = true;
      //Object.assign 克隆
      this.systemdictionarytypeForm = Object.assign({}, row);//回显
     
    },
    //显示新增界面
    handleAdd: function () {
       
      this.yoyo="新增";
      this.systemdictionarytypeFormVisible = true;
      this.systemdictionarytypeForm = {//清空历史遗留数据
        id: null,
        sn: "",
        name: "",
        state: 0,
        manager: null,
        parent: null,
      };
    },




    //编辑
    systemdictionarytypeSubmit: function () {
      this.$refs.systemdictionarytypeForm.validate((valid) => {
        if (valid) {
          this.$confirm('确认提交吗？', '提示', {}).then(() => {
            this.systemdictionarytypeLoading = true;
            //NProgress.start();
            let para = Object.assign({}, this.systemdictionarytypeForm);
           //下午要用
            if(para.parent){
              para.parent={"id":parseInt(para.parent[para.parent.length-1])};
            }
            this.$http.put("/systemdictionarytype",para)
                .then(result=>{
                  //1.关闭忙等
                  this.listLoading = false;
                  //判断业务操作是否正常
                  result  = result.data;//AjaxResult  {success:false,message:操作失败}
                  if(result.success){
                    this.systemdictionarytypeLoading = false;
                    this.systemdictionarytypeFormVisible = false;
                    this.$message({
                      message: '操作成功',
                      type: 'success'
                    });
                  }else{
                    this.systemdictionarytypeLoading = false;
                    this.$message({
                      message: result.message,//提示我们自己的业务错
                      type: 'error'
                    });
                  }
                  //2.刷新页面
                  //是否需要重新刷新页面   要  定位到第一页
                  this.currentPage= 1;
                  this.filters.keyword="";
                  this.getSystemdictionarytype();
                })
                 .catch(result=>{
                   this.systemdictionarytypeLoading = false;
                  //NProgress.done();
                  this.$message({
                    message: '操作失败',
                     type: 'error'
                  });
                  //失败了是否需要重新刷新页面   要  定位到第一页
                   this.currentPage= 1;
                   this.filters.keyword="";
                   this.getSystemdictionarytype();
                 })
          });
        }
      });
    },
    selsChange: function (sels) {//当前已经选中的所有行的数据
      this.sels = sels;
    },
    selsChan:function (sels) {
      this.se = sels;
    },







    bat: function () {
      var ids = this.se.map(item => item.id);//[1,2,3]
      this.$confirm('确认删除选中记录吗？', '温馨提示', {
        type: 'warning'
      }).then(() => {
        this.listb = true;
        //NProgress.start();
        this.$http.patch("/systemdictionarydetail",ids)
            .then(result=>{
              //1.关闭忙等
              this.listb = false;
              //判断业务操作是否正常
              result  = result.data;//AjaxResult  {success:false,message:操作失败}
              if(result.success){
                this.$message({
                  message: '删除成功',
                  type: 'success'
                });
              }else{
                this.$message({
                  message: result.message,//提示我们自己的业务错
                  type: 'error'
                });
              }
              //2.刷新页面
              //是否需要重新刷新页面   要  定位到第一页
              this.currentPage= 1;
              this.getids();
            })
            .catch(result=>{
              this.listb = false;
              //NProgress.done();
              this.$message({
                message: '删除失败',
                type: 'error'
              });
              //失败了是否需要重新刷新页面   要  定位到第一页
              this.currentPage= 1;
              this.getids();
            })
      }).catch(() => {

      });
    },



















    //批量删除
    batchRemove: function () {
      var ids = this.sels.map(item => item.id);//[1,2,3]
      this.$confirm('确认删除选中记录吗？', '温馨提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        //NProgress.start();
        this.$http.patch("/systemdictionarytype",ids)
            .then(result=>{
              //1.关闭忙等
              this.listLoading = false;
              //判断业务操作是否正常
              result  = result.data;//AjaxResult  {success:false,message:操作失败}
              if(result.success){
                this.$message({
                  message: '删除成功',
                  type: 'success'
                });
              }else{
                this.$message({
                  message: result.message,//提示我们自己的业务错
                  type: 'error'
                });
              }
              //2.刷新页面
              //是否需要重新刷新页面   要  定位到第一页
              this.idage= 1;
              this.getSystemdictionarytype();
            })
            .catch(result=>{
              this.listLoading = false;
              //NProgress.done();
              this.$message({
                message: '删除失败',
                type: 'error'
              });
              //失败了是否需要重新刷新页面   要  定位到第一页
              this.idage= 1;
              this.getSystemdictionarytype();
            })
      }).catch(() => {

      });
    },
    getids(){
      this.listLoading = true;//开启忙等框
      this.$http.get("/systemdictionarydetail/"+this.ids)
          .then(result=>{
            result = result.data;//PageList{total rows}

            this.systemdictionarydetails = result;
            /*console.log( this.systemdictionarydetails)*/
            this.listLoading = false;//关闭忙等框
            this.tot = result.tot;

          })
          .catch(result=>{
            console.log(result);
            alert("系统错误！");
          })
    },


  },


  mounted() {
    this.getSystemdictionarytype();
    this.getSystemdictionarydetail();

  }
}

</script>

<style scoped>


</style>